/*
* 选择复检部门
* */
import 'package:center_beijing/api/task_api.dart';
import 'package:center_beijing/common/logutil.dart';
import 'package:center_beijing/common/styles.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';

class SelectDepartment extends StatefulWidget {
  @override
  _SelectDepartmentState createState() => _SelectDepartmentState();
}

class _SelectDepartmentState extends State<SelectDepartment>
    with SingleTickerProviderStateMixin {
  AnimationController _controller;
  List allItemList = [];
  var type = Get.arguments;
  @override
  void initState() {
    _controller = AnimationController(vsync: this);
    super.initState();
    this.getDepartment();
  }

  @override
  void dispose() {
    _controller.dispose();
    super.dispose();
  }

  /*
  * 获取部门
  * */
  getDepartment() async {
    var result = await getFlowDapts({
      'issueType': type,
    });
    if (result != null && result.length > 0) {
      this.setState(() {
        allItemList = result;
      });
    }
    LogUtil.d(result);
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('部门选择'),
      ),
      body: Container(
        color: Styles.MainBackgroundColor,
        padding:
            EdgeInsets.fromLTRB(0, 0, 0, MediaQuery.of(context).padding.bottom),
        child: SingleChildScrollView(
          child: Column(
            children: this.allItemList.map<Widget>((item) {
              return GestureDetector(
                behavior: HitTestBehavior.translucent,
                onTap: () {
                  // this.setState(() {
                  //   item['selected'] =
                  //   item['selected'] == null ? true : !item['selected'];
                  // });
                  Get.back(result: item);
                },
                child: Container(
                  decoration: BoxDecoration(
                      border: Border(
                          bottom:
                              BorderSide(color: Styles.GrayLight, width: 1))),
                  padding: EdgeInsets.fromLTRB(Styles.spacing16,
                      Styles.spacing16, Styles.spacing16, Styles.spacing16),
                  child: Row(
                    children: [
                      // Container(
                      //   padding:
                      //   EdgeInsets.fromLTRB(0, 0, Styles.spacing8, 0),
                      //   child: Image.asset(
                      //     (item['selected'] != null && item['selected'])
                      //         ? "assets/images/group_selected.png"
                      //         : "assets/images/group_select.png",
                      //     width: 20.w,
                      //     height: 20.h,
                      //     fit: BoxFit.contain,
                      //   ),
                      // ),
                      Expanded(
                          child: Text(
                        item['name'],
                        style: TextStyle(
                            color: Styles.DetailColor,
                            fontSize: Styles.Middle16Font),
                      )),
                    ],
                  ),
                ),
              );
            }).toList(),
          ),
        ),
      ),
    );
  }
}
